package com.jeesite.modules.isys.common.aop.dict;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.modules.isys.common.aop.query.NullExec;
import com.jeesite.modules.isys.common.aop.check.CheckObject;
import com.jeesite.modules.isys.common.entity.MyPage;
import com.jeesite.modules.isys.common.entity.Result;
import com.jeesite.modules.sys.utils.DictUtils;
import com.jeesite.modules.isys.common.entity.Res;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;



@Aspect
@Component
@Slf4j
public class SysDictAop {

    @Autowired
    private NullExec nullExec;

    @Autowired
    private CheckObject checkObject;

    //    execution(* com.jeesite.modules.tb..*Controller.*(..))
    @Pointcut("execution(* com.jeesite.modules.isys..*Controller.*(..))")
    public void dict() {
    }


    @Around("dict()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        try {
//            String dictLabel = DictUtils.getDictLabel("cms_source ", "1", "原创");
//            System.out.println("around");
            //下面需要判断参数是否需要进行处理
            return proceed(joinPoint);
        } catch (Throwable e) {
            e.printStackTrace();
            throw e;
        } finally {
            System.out.println("around");
        }
    }


    //综合处理
    private Object proceed(ProceedingJoinPoint joinPoint) throws Throwable {
        //处理参数
        Object[] args = joinPoint.getArgs();
        for (int i = 0;i<args.length;i++){
            args[i] = checkObject.checkArg(args[i]);
        }

        //获取结果
        Object proceed = joinPoint.proceed();



        //处理结果
        proceed = checkObject.check(proceed);


        return proceed;
    }
}